import http from "@/utils/http";
import type {
  ProductReturnAddParamsType,
  ProductReturnListParamsType,
  ProductReturnUpdateParamsType,
  PaginationType
} from "./params";
import { headerCommon, headerMaster } from "../header";
import {
  ProductReturnAddResponseData,
  ProductReturnResponseData,
  ProductReturnUpdateResponseData,
} from "./res";

// 标准写法
enum API {
  GET_PRODUCTRETURN_List_API = "/1.1/classes/productReturn",
  POST_PRODUCTRETURN_ADD_API = "/1.1/classes/productReturn",
  DELETE_PRODUCTRETURN_API = "/1.1/classes/productReturn",
  PUT_PRODUCTRETURN_UPDATE_API = "/1.1/classes/productReturn",
}

// example
//获取生产退料列表
export const getProductReturnListApi = (data?: ProductReturnListParamsType, params?: PaginationType) =>
  http.get<any, ProductReturnResponseData>(
    API.GET_PRODUCTRETURN_List_API +
    `${data ? `?where=${JSON.stringify(data)}` : ""}`,
    {
      headers: headerCommon,
      ...(params ? { params: { limit: params.pageSize, skip: (params.currentPage - 1) * params.pageSize } } : {})
    }
  );

//新增生产退料
export const postProductReturnAddApi = (data: ProductReturnAddParamsType) =>
  http.post<any, ProductReturnAddResponseData>(
    API.POST_PRODUCTRETURN_ADD_API,
    data,
    {
      headers: headerCommon,
    }
  );

//更新生产退料
export const putProductReturnUpdateApi = (
  data: ProductReturnUpdateParamsType
) =>
  http.put<any, ProductReturnUpdateResponseData>(
    API.PUT_PRODUCTRETURN_UPDATE_API + `/${data.objectId}`,
    data,
    {
      headers: headerMaster,
    }
  );

// 删除生产退料
export const deleteProductReturnApi = (objectId: string) =>
  http.delete<any, any>(API.DELETE_PRODUCTRETURN_API + `/${objectId}`, {
    headers: headerMaster,
  });
